﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using LiveChartsCore;
using LiveChartsCore.Drawing;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.SkiaSharpView.WinForms;
using LiveChartsCore.SkiaSharpView.VisualElements;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using SkiaSharp;
using System.Collections.ObjectModel;

namespace TCOChart
{
    public partial class Form1 : Form
    {
        private LineSeries<ObservableValue> m_lineSeries { get; set; }
        private ColumnSeries<ObservableValue> m_onepass_columnSeries { get; set; }
        private StepLineSeries<ObservableValue> m_time_stepline { get; set; }

        public ISeries[] Series { get; set; }

        public Form1()
        {
            InitializeComponent();
            //FormLogin formLogin = new FormLogin();

            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void cartesianChart1_Load(object sender, EventArgs e)
        {
            m_lineSeries = new LineSeries<ObservableValue>()
            {
                Name = "直通率(%)",
                Values = new ObservableCollection<ObservableValue>(),
                DataLabelsPosition = LiveChartsCore.Measure.DataLabelsPosition.Bottom,  // 数值显示位置
                DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),  // 设置显示在图形中的数值颜色
                LineSmoothness = 1,  // 设置曲线的平滑性， 0--1，由直到弯曲
                Fill = new SolidColorPaint(new SKColor(20, 200, 200, 128)),  // 设置图形填充，折线的下部分进行填充
                Stroke = new SolidColorPaint(new SKColor(45, 45, 45)) { StrokeThickness = 5 },
                IsHoverable = true,
            };

            m_onepass_columnSeries = new ColumnSeries<ObservableValue>()
            {
                Name = "一次PASS",
                Values = new ObservableCollection<ObservableValue>(),
                ScalesYAt = 0,
                DataLabelsPosition = LiveChartsCore.Measure.DataLabelsPosition.Top,  // 数值显示位置
                DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),  // 设置显示在图形中的数值颜色
                IgnoresBarPosition = true,
                MaxBarWidth = 20,
                Stroke = null,
                Ry = 5,
                Rx = 5,
            };

            m_time_stepline = new StepLineSeries<ObservableValue>()
            {
                Name = "time",
                Values = new ObservableCollection<ObservableValue>(),
                ScalesYAt = 0,
                //DataLabelsFormatter = value => (value.Coordinate.PrimaryValue / 100).ToString("P"),
                //YToolTipLabelFormatter = point => point.Model.ToString()
            };

            List<int> ints = new List<int>() { 1, 3, 2, 5, 6 ,8, 2};
            m_lineSeries.Values = ints.Select(value=>new ObservableValue(value)).ToList();

            m_time_stepline.Values = ints.Select(value=>new ObservableValue(value)).ToList();

            cartesianChart1.XAxes = [
                    new Axis{
                    TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),  // 刻度线颜色
                    TicksAtCenter = true,  // 是否位于中间
                    MinStep = 1,
                    SeparatorsPaint = new SolidColorPaint(new SKColor(200, 20, 200)),
                    Name = "X",

                    CrosshairLabelsBackground = SKColors.DarkOrange.AsLvcColor(),
                    CrosshairLabelsPaint = new SolidColorPaint(SKColors.DarkRed),
                    CrosshairPaint = new SolidColorPaint(SKColors.DarkOrange, 1),
                    Labeler = value => value.ToString("N3"),
                    MaxLimit = 5,
                    MinLimit = 0,
                }];
            cartesianChart1.YAxes = [
                new Axis{
                    TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),  // 刻度线颜色
                    TicksAtCenter = true,  // 是否位于中间
                    SeparatorsPaint = new SolidColorPaint(new SKColor(200, 200, 200)),
                    Position = LiveChartsCore.Measure.AxisPosition.Start,
                    MinLimit = 0,
                    },
                    new Axis{
                    //TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),  // 刻度线颜色
                    //TicksAtCenter = true,  // 是否位于中间
                    //SeparatorsPaint = new SolidColorPaint(new SKColor(200, 200, 200)),
                    Position = LiveChartsCore.Measure.AxisPosition.End,
                    Labeler = (value) => (value/100).ToString("P"),
                    //MinStep = 1,  // 最小步长
                    MinLimit = 0,  // 最小范围
                    //Name = "P"
                    ShowSeparatorLines = true,
                }
            ];
            Series = [m_time_stepline];
            cartesianChart1.Series = Series;
            //cartesianChart1.Title = 
        }
    }
}
